<?php
namespace App\Models\Traits;
use Ip2Region;
trait UserRegisterCityHelper{
    public function setUserRegisterCity(){
        //获取用户的注册地地址
        $ip2region = new Ip2Region();
        $ip = request()->getClientIp();
        $info = $ip2region->binarySearch($ip);
        $city_arr = explode("|",$info['region']);
        $city = $city_arr[2];
        if ($city=="0"){
            $city = $city_arr[3];
        }
        $this->ip_addr = $ip;
        if ($this->city!=0){
            $this->city = $city;
        }
        $this->save();
    }
}
